<?php

Zend_Loader::loadClass("Application_Page");
Zend_Loader::loadClass("Application_Menu_Preprocessor");
Zend_Loader::loadClass("Application_Navigation_Preprocessor");

class Application_Page_Simulazioni extends Application_Page
{
	private $_leftCol;
	private $_rightCol;

	protected function _init()
	{
		parent::_init();
		Zend_Layout::getMvcInstance()->setLayout('simulazioni');
		$this->addJavascript("/lib/plugins/jquery.uniform.custom.js");
	}

	public function run()
	{

		$headNav = new Application_Navigation_Preprocessor();
		$menuNav = new Application_Menu_Preprocessor();

		$headNav->run();
        $menuNav->run();

		Zend_Layout::getMvcInstance()->section = "Gestione simulazioni";
		Zend_Layout::getMvcInstance()->topRow = $headNav->render();
		Zend_Layout::getMvcInstance()->sidebar = $menuNav->render();

        Zend_Loader::loadClass('Simulations');
        Zend_Loader::loadClass('Runs');
        $simulations = new Simulations();
        $runs = new Runs();

        $select = $simulations->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
        $select->setIntegrityCheck(false)
            ->joinLeft('run', "simulation.id = run.id_simulation", array(
                "sim_id" => "simulation.id",
                "simulation.sim_name",
                "simulation.sim_submit_date",
                "run_id" => "run.id",
                "run_date",
                "run_status"))
            ->where("simulation.sim_status > ?", 0)
            ->order("simulation.sim_name")
        ;

        $this->_view->simulations = $simulations->fetchAll($select);
        //var_dump($this->_view->simulations); exit;

        Zend_Layout::getMvcInstance()->rightCol = $this->render();
    }
}
